Skip to content

feat: native Anthropic passthrough for Claude models#246

Open
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
jackylam0812:feat/native-anthropic-passthrough
Open

feat: native Anthropic passthrough for Claude models#246
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
jackylam0812:feat/native-anthropic-passthrough

Conversation

@jackylam0812
Copy link
Copy Markdown

Summary

Route Claude model requests directly to Copilot's native /v1/messages endpoint instead of translating through OpenAI /chat/completions.

Motivation

The current architecture translates every request through an Anthropic ↔ OpenAI format conversion layer. However, GitHub Copilot exposes a native Anthropic /v1/messages endpoint that accepts Claude requests directly. By bypassing the translation for Claude models, we get:

  • Zero translation overhead — requests/responses pass through unchanged
  • Native thinking supportthinking.type: "adaptive" works out of the box
  • Native cache_control — prompt caching via Anthropic semantics
  • Native output_config — effort levels supported natively
  • Simpler streaming — SSE pipes directly without chunk-by-chunk translation

Changes

New files

  • src/lib/sanitize.ts — Copilot backend compatibility sanitizer
    • Strips unsupported fields (context_management, budget_tokens, defer_loading, tool_reference)
    • opus models: thinking.enabledadaptive, effort → medium
    • Model name normalization (claude-sonnet-4-*claude-sonnet-4)
  • src/services/copilot/create-messages.ts — Native /v1/messages client
  • tests/sanitize.test.ts — 16 test cases for the sanitizer

Modified

  • src/routes/messages/handler.ts — Routes Claude models to native path, non-Claude models keep existing OpenAI translation

Routing logic

Client (Anthropic format)
  → handler.ts
    ├─ Claude models → sanitize → /v1/messages (native, zero translation)
    └─ Non-Claude   → translateToOpenAI → /chat/completions (existing path)

Test results

All 42 tests pass (26 existing + 16 new sanitizer tests).

Breaking changes

None. Non-Claude models (GPT, etc.) are completely unaffected.

Route Claude model requests directly to Copilot's native /v1/messages
endpoint instead of translating through OpenAI /chat/completions.

Benefits:
- Eliminates Anthropic↔OpenAI translation overhead for Claude models
- Enables native thinking (adaptive), cache_control, output_config
- Streaming SSE directly piped (zero translation latency)
- Non-Claude models (GPT etc.) keep existing OpenAI translation path

New files:
- src/services/copilot/create-messages.ts - Native /v1/messages client
- src/lib/sanitize.ts - Copilot backend compatibility sanitizer
  - Strips unsupported fields (context_management, budget_tokens, etc.)
  - opus: thinking.enabled→adaptive, effort→medium
  - Model name normalization (claude-sonnet-4-* → claude-sonnet-4)

Modified:
- src/routes/messages/handler.ts - Route Claude vs non-Claude models

All 42 existing + new tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant